package com.huawei.baidutranslator;

/**
 * @description:
 * @author: lhh
 * @time: 2022/6/7
 */

import java.util.HashMap;
import java.util.Scanner;

public class translator {
    public static void main(String[] args) {
        //定义Map集合用于存储词典的数据
        HashMap<String, String> word = new HashMap<String, String>();
        while(true) {
        //集合合添加词典的数据。
            word.put("alter","改变");
            word.put("vague"," 模糊的");
            word.put("budget","预算");
            word.put("candidate","候选人");
            word.put("campus","校园");
            word.put("apple", "苹果");
            word.put("banner", "香蕉");
            word.put("book", "书");
            word.put("telephone", "电话");
            word.put("cat", "猫");
            word.put("dog", "狗");
            word.put("smart kid","聪明小孩");
            word.put("student", "学生");
            word.put("teacher", "老师");
            word.put("transmit ","传播");
            word.put("nuisance","损害");
            word.put("boundary","边界");
            word.put("java","爪哇");

        //键盘录入功能获取我们要翻译的单词
            Scanner sc = new Scanner(System.in);
            System.out.println("请您输入您要翻译的单词：");
            String w = sc.nextLine();
            //调用判断打印输出
            Select(w, word);
            //调用Select()方法实现集合中判断是否包含键盘输入的单词，如果有则输入对应的中文意思，反之则给出相应提示。
         }
            }
        //定义方法对键盘录入的数据进行判断
        public static String Select(String w, HashMap<String, String> word) {
            if(w.isEmpty()) {
                System.out.println("请输入您要翻译的单词：");
                return "";
                }else if(!word.containsKey(w)) {
                System.out.println("对不起，您要翻译的单词不存在，请重新输入：");
                }else{
                String chinese = word.get(w);
                System.out.println(w+"翻译成中文意思为："+chinese);
                }
                return w;
        }
}
